package com.rural.bus.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.baidu.location.Poi;
import com.rural.bus.R;
import com.rural.bus.model.MyPoiInfo;

public class NearPoiAdapter extends BaseAdapter {
	private Context context;
	public List<MyPoiInfo> lists;
	private LayoutInflater mInflater;

	public NearPoiAdapter(Context context, List<MyPoiInfo> lists) {
		this.context = context;
		this.lists = lists;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return lists == null ? 0 : lists.size();
	}

	@Override
	public MyPoiInfo getItem(int position) {
		if (lists != null && lists.size() != 0) {
			return lists.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater
					.inflate(R.layout.list_item_near_poi, null);
			holder = new ViewHolder();
			holder.tv_near_poi_name = (TextView) convertView
					.findViewById(R.id.tv_near_poi_name);
			holder.tv_near_poi_address = (TextView) convertView.findViewById(R.id.tv_near_poi_address);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.tv_near_poi_name.setText(""+lists.get(position).name);
		holder.tv_near_poi_address.setText(""+lists.get(position).address);

		return convertView;
	}

	public class ViewHolder {
		public TextView tv_near_poi_name;
		public TextView tv_near_poi_address;
	}

}
